<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
	
<ui:composition template="/pages/template/padrao.xhtml">
<ui:define name="principal">
	<f:view>
	<center>
		<!-- Nova Midia -->
		<h:form>
			<h:commandLink value="Nova Mídia" action="#{controlMidia.mostrarNovo}" />
		</h:form>
		
		<h:form id="novoMidia" binding="#{controlMidia.formNovo}" rendered="false">
			<h:panelGrid columns="2">
				<h:outputText value="Jogo" />
				<h:selectOneMenu value="#{controlMidia.midia.jogo.idJogo}">
					<f:selectItems value="#{controlMidia.listaJogos}" />
				</h:selectOneMenu>
				
				<h:outputText value="Data Compra" />
				<h:inputText value="#{controlMidia.midia.dataCompra}" required="true" converter="javax.faces.DateTime" />
				
				<h:outputText value="Valor Compra" />
				<h:inputText value="#{controlMidia.midia.valorCompra}" required="true" />
			</h:panelGrid>
			<h:panelGroup>
				<h:commandButton value="Inserir" action="#{controlMidia.inserir}" />
			</h:panelGroup>
			<h:messages />
		</h:form>
		
		<h:messages />

		<!-- Lista de Midias -->
		<h:form>
			<h:dataTable value="#{controlMidia.listaMidias}" var="mid" border="1">
				<f:facet name="header">
					<h:outputText value="Midias" />
				</f:facet>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Jogo" />
					</f:facet>
					<h:outputText value="#{mid.jogo.nome}" />
				</h:column>
				
				<h:column>
					<f:facet name="header">
						<h:outputText value="Console" />
					</f:facet>
					<h:outputText value="#{mid.jogo.console.nome}" />
				</h:column>

				<h:column>
					<f:facet name="header">
						<h:outputText value="Data Compra" />
					</f:facet>
					<h:outputText value="#{mid.dataCompra}" />
				</h:column>

				<h:column>
					<f:facet name="header">
						<h:outputText value="Valor Compra" />
					</f:facet>
					<h:outputText value="#{mid.valorCompra}" />
				</h:column>

				<h:column>
					<f:facet name="header">
						<h:outputText value="Excluir" />
					</f:facet>
					<h:commandLink value="Excluir" action="#{controlMidia.excluir}">
						<f:setPropertyActionListener value="#{mid}" target="#{controlMidia.midia}"/>
					</h:commandLink>
				</h:column>
			</h:dataTable>
		</h:form>
		<h:outputLink value="#{facesContext.externalContext.requestContextPath}/pages/inicial.jsf" >
			<f:verbatim>Voltar</f:verbatim>
		</h:outputLink>
	</center>
	</f:view>
</ui:define>
</ui:composition>
</html>